<template>
  <!-- 1.0首页个人信息 -->
  <div class="container">
    <div class="info-box">
      <van-image
        :src="userInfo.photo"
        width="64px"
        height="64px"
        fit="cover"
        round
      />
      <h2>
        {{ userInfo.name }}
        <br />
        <van-tag color="#fff" text-color="#009afa">{{
          userInfo.birthday
        }}</van-tag>
      </h2>
    </div>
    <!-- 2.0个人操作 -->
    <div class="user-link">
      <van-row>
        <van-col span="8">
          <van-icon name="coupon-o" color="#2ec1ed" size="25px" />
          <br />
          我的作品
        </van-col>
        <van-col span="8">
          <van-icon name="star-o" color="#ff7183" size="25px" />
          <br />
          我的收藏
        </van-col>
        <van-col span="8">
          <van-icon name="todo-list-o" color="#f9ca6f" size="25px" />
          <br />
          阅读历史
        </van-col>
      </van-row>
    </div>
    <!-- 系统操作 -->
    <div>
      <van-cell-group>
        <van-cell title="编辑资料" icon="edit" is-link to="/eait" />
        <van-cell title="小智同学" icon="chat-o" is-link to="/student" />
        <van-cell title="系统设置" icon="setting-o" is-link />
        <van-cell
          title="退出登陆"
          icon="warning-o"
          is-link
          @click="getOutclick"
        />
      </van-cell-group>
    </div>
  </div>
</template>

<script>
//导入请求个人信息网络中间层
import { getUserinfo } from "./user.js";
//导入清空token接口
import { removeToken } from "@/utils/token.js";
export default {
  name: "user",
  data() {
    return {
      //绑定数据
      userInfo: {},
    };
  },
  created() {
    getUserinfo().then((res) => {
      // console.log(res);
      //  数据绑定
      this.userInfo = res.data.data;
      //数据储存到state
      this.$store.commit("userInfodata", res.data.data);
    });
  },
  methods: {
    getOutclick() {
      // 弹出框
      this.$dialog
        .confirm({
          title: "温馨提示",
          message: "确认退出吗?",
        })
        .then(() => {
          //清空token
          removeToken();
          //清空个人信息
          this.userInfo = {};
          //跳转回login页
          this.$router.push({ path: "/login" });
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang="less">
.container {
  .info-box {
    display: flex;
    align-items: center;
    height: 100px;
    background-color: #009afa;

    .van-image {
      margin: 0 20px;
    }
    h2 {
      font-size: 15px;
      font-weight: 400;
      color: #fff;
    }
  }
}
.user-link {
  text-align: center;
  font-size: 14px;
  padding: 15px 0;
}
</style>